<% results.each do |comment| %>

  <p>
    <span class="sn-icon sn-icon-comments"></span>
    <% if comment.is_a?(ProjectComment) && comment.project.present? %>
      <%=t "search.index.comments.project" %>
    <% elsif comment.is_a?(TaskComment) && comment.my_module.present? %>
      <%=t "search.index.comments.my_module" %>
    <% elsif comment.is_a?(StepComment) && comment.step.present? %>
      <%=t "search.index.comments.step" %>
    <% elsif comment.is_a?(ResultComment) && comment.result.present? %>
      <%=t "search.index.comments.result" %>
    <% end %>
  </p>
  <div class="row">
    <p class="chat-bubble col-xs-4">
      <%= highlight comment.message, @search_query.strip.split(/\s+/) %>
    </p>
  </div>
  <p>
    <span>
      <%=t "search.index.created_by" %>
      <%= highlight comment.user.full_name, @search_query.strip.split(/\s+/) %>
    </span>
    <br>
    <span>
      <%=t "search.index.created_at" %>
      <%=l comment.created_at, format: :full %>
    </span>
    <br>
  </p>

  <p>
    <% if comment.is_a?(ProjectComment) && comment.project.present? %>
      <% project = comment.project %>
    <% elsif comment.is_a?(TaskComment) && comment.my_module.present? %>
      <% my_module = comment.my_module %>
      <% experiment = my_module.experiment %>
      <% project = experiment.project %>
    <% elsif comment.is_a?(StepComment) && comment.step.present? %>
      <% step = comment.step %>
      <% my_module = step.protocol.my_module %>
      <% experiment = my_module.experiment %>
      <% project = experiment.project %>
    <% elsif comment.is_a?(ResultComment) && comment.result.present? %>
      <% result = comment.result %>
      <% my_module = result.my_module %>
      <% experiment = my_module.experiment %>
      <% project = experiment.project %>
    <% end %>




    <% if result %>
      <span>
        <%=t "search.index.result" %>
        <%= render partial: "search/results/partials/result_text",
                   locals: { result: result, target: :comment } %>
      </span>
      <br>
    <% end %>

    <% if step %>
      <span>
        <%=t "search.index.step" %>
        <%= render partial: "search/results/partials/step_text",
                   locals: { step: step, target: :comment } %>
      </span>
      <br>
    <% end %>

    <% if my_module %>
      <span>
        <%=t "search.index.module" %>
        <%= render partial: "search/results/partials/my_module_text",
                   locals: { my_module: my_module, link_to_page: :canvas } %>
      </span>
      <br>
    <% end %>

    <% if experiment %>
      <span>
        <%=t "search.index.experiment" %>
        <%= render partial: "search/results/partials/experiment_text",
                   locals: { experiment: experiment } %>
      </span>
      <br>
    <% end %>

    <span>
      <%=t "search.index.project" %>
      <%= render partial: "search/results/partials/project_text",
                 locals: { project: project, link_to_page: :show } %>
    </span>
    <br>
    <span>
      <%=t "search.index.team" %>
      <%= render partial: "search/results/partials/team_text",
                 locals: { team: project.team } %>
    </span>
  </p>

  <hr>
<% end %>
